*===============================================================================
*
*					WORKER BELIEFS ABOUT OUTSIDE OPTIONS
*		(c)	Simon Jaeger, Christopher Roth, Nina Roussille, Benjamin Schoefer
*							  2023 December 5
*						   	   	 Local Data 
*
*===============================================================================


********************************************************************************
*								Table F03									   *
********************************************************************************

use "$temp/GSOEPIS_survey_reshaped.dta", clear

keep if syear == 19 & monetary_surplus!=.

*Generate Measurement of Bias Belief (For each year)
gen bias_belief_pct = (salary_guess - salary_median) / salary_median

* Measurement of Beliefs is negative of monetary rent:
gen beliefs_pct_w2 = - monetary_surplus_pct_w2

* Generate treatment extended to all observations
bys pid : egen treated_info=max(treat)

* Interaction term = treated*bias
gen bias_treated = treated_info*bias_belief_pct

* Recoding 
gen negotiate_pct_z = negotiate_pct
recode negotiate_pct_z (. = 0)
	
*Rescaling beliefs

replace beliefs_pct_w2 = beliefs_pct_w2/ 100

*Rescaling LM Behaviors

foreach x in switchout_proba negotiate_proba negotiate_pct_z negotiate_pct paycut_quit_pct{
	
	replace `x' =  `x' / 100
}

gen y=1
	
* control group mean bias_belief_pct
su beliefs_pct_w2 if treated_info==0


********************************************************************************
* Table A09
********************************************************************************

loc lhs "beliefs_pct_w2 switchout_proba negotiate_proba  negotiate_pct_z negotiate_pct paycut_quit_pct"

local i=0

foreach vari in `lhs' {
    loc ++i
	reg `vari' bias_belief_pct treated_info bias_treated, cluster(pid)
	estimates store estim_`i'
	estadd local constant = round(_b[_cons],0.02)
	local n_`i' = e(N)
}

esttab estim_1 estim_2 estim_3 estim_4 estim_5 estim_6  ///
	using "$tab/TableF03.tex", replace ///
	starlevels(* 0.1  ** 0.05 *** 0.01)  ///
	cells("b(fmt(3) star)" se(par(( ))fmt(3)))  ///
	nodep legend frag label ///
	varlabel(bias_treated "\textbf{Treated $\times$ Pre-Treat Estimation Error}" ///
	treated_info "\textbf{Treated}" ///
	bias_belief_pct "\textbf{Pre-Treat Estimation Error}" ///
	_cons "\textbf{Constant}" ) ///
	keep(bias_treated treated_info bias_belief_pct _cons) ///
	order(bias_treated treated_info bias_belief_pct) ///
	nomtitles  mlabels("Post-Treat:" "Intended" "Intended" "Intended Neg." "Intended Neg." ///
	"Reservation \\ & Outside Option & Search & Negotiation & Magnitude & Magnitude & Wage Cut \\ & (Wage Change) & Probability & Probability & (No Neg. = 0) & (No Neg. = Msg.) & ") ///
	collabels(none)	///
	substitute("Observations        &         `n_1'   &         `n_2'   &         `n_3'   &         `n_4'   &         `n_5'   &         `n_6'   \\" "" "\hline" "" "\textbf{Treated $" "\hline \\ \textbf{Treated $") // drop observation row and extra hline
	
	
	
*** IV regression 

eststo clear 
			
local x=1
				
foreach xvar in switchout_proba negotiate_proba negotiate_pct_z negotiate_pct paycut_quit_pct{
			
	local ++x

	sum `xvar' if treated_info==0
	scalar mean = r(mean)
	ivregress 2sls `xvar' bias_belief_pct (beliefs_pct_w2 = treated_info bias_treated), cluster(pid)
	estimates store estim_`x'
	estadd scalar mean
	
	estat firststage
	mat fstat = r(singleresults)
	estadd scalar fs = fstat[1,4] 
	estadd scalar num = e(N)

	local se_`x' `: di %5.3fc _se[beliefs_pct_w2]'
	
}
							
*first column 
reg y y beliefs_pct_w2, nocons
estimates store estim_1	
su beliefs_pct_w2 if treated_info==0
local m_1 = `: di %5.3fc r(mean)'

esttab estim_1 estim_2 estim_3 estim_4 estim_5 estim_6 ///
	using "$tab/TableF03.tex", append frag ///
	starlevels(* 0.1  ** 0.05 *** 0.01) cells("b(fmt(3) star)" se(par(( ))fmt(3)))  ///
	nodep legend label collabels(none) ///
	varlabels(beliefs_pct_w2 "\textbf{IV: Endogenous Variable}" ///
	_cons "\textbf{Constant}") ///
	keep(beliefs_pct_w2 _cons) ///
	order(beliefs_pct_w2 _cons) ///
	mtitles(none) mlabels(none) nonumbers scalars(fs) /// 
	stats(mean fs  num, fm(%05.3f 3 %8.0fc) ///
	labels("\textbf{Control Group Mean}" "\textbf{First-Stage F-Stat}" "\textbf{N}")) ///
	substitute("&      -0.000   &" "&&" "(.)" " " "                    &             &     (`se_2')   &" "\textbf{Belief About Outside Option (Wage Change)}    &             &     (`se_2')   &" "\textbf{N}          &               &" "\textbf{N}          &     `n_1'    &" "\textbf{Control Group Mean}&               &" "\textbf{Control Group Mean}&      `m_1'     &") // this last substitution is to add the line "Belief About Outside Option (Wage Change)" on the line of the standard errors	
	
